Skip to content

feat(pm-agg): C4.4 arrival prediction records — honesty-first emission, validation, scoring (#13260) - #13299

Merged
dezren39 merged 1 commit into
mainfrom
lane-we-13260
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
lane-we-13260

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Part of #13260 (C4.4, component of #9572). One bounded slice: the model_plan_arrival record contract from the C4 design record (§1/§3/§7), as a pure module in the quota-anomaly.ts discipline.

What lands — pm-stack/aggregator/src/quota-arrival.ts:

  • buildArrivalRecords — one predicted record per named basis that can honestly bound a range: detector_history (the pool's S5 plan-change findings read as arrival instants; ≥2 spread intervals bound the next arrival, median as likely) and vendor_cadence (a cadence actually recorded, with a measured spread; stale anchors roll forward). One interval, identical intervals, or a spread-less recorded period yield the insufficient_history honesty state; no evidence at all yields the explicit no_basis state with every absence named. Bases are never blended.
  • validateArrivalRecord — enforces the contract; the builder runs every emitted record through it. A predicted record must name a real basis and a strictly bounded range (a point date is refused); an honesty-state record must carry no range at all. A record without a basis is never published — no speculative date can leave the module.
  • scoreArrivalPrediction — hit/miss plus lead time on hits (§3); honesty-state records are never scored; open predictions are unscored, never assumed.
  • renderPredictionRange — §4 duration/day forms, stored on the record at issuance.

Tests — src/quota-arrival.test.ts, 20 tests naming the design record as oracle: 20 pass; bunx tsc --noEmit clean; neighbouring quota suites (anomaly, forecast) green.

Remainder for #13260 (issue stays open): the live wiring — gatherer tick emitting records to quota-predictions.jsonl with the Turso mirror under source quota-prediction (the constant is exported here for exactly one spelling) — first scored outcomes against live arrivals, and §4's calendar rendering form.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…n, validation, scoring (#13260)

New pure module pm-stack/aggregator/src/quota-arrival.ts implementing
the model_plan_arrival kind of the C4 prediction record (design
doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/
c4-forecasting-design.md §1/§3/§7):

- buildArrivalRecords: one predicted record per named basis that can
  honestly bound a range — detector_history (the pool's S5 plan-change
  findings read as arrival instants; >=2 spread intervals bound the
  next arrival) and vendor_cadence (a cadence actually recorded, with
  a measured spread). One interval, identical intervals, or a
  spread-less recorded period are the insufficient_history honesty
  state; no evidence at all is the explicit no_basis state with every
  absence named. Bases are never blended.
- validateArrivalRecord enforces the contract and the builder runs
  every emitted record through it: a predicted record must name a
  real basis and a strictly bounded range (a point date is refused);
  an honesty-state record must carry no range at all — a record
  without a basis is never published, so no speculative date can
  leave the module.
- scoreArrivalPrediction: hit/miss plus lead time on hits (§3);
  honesty-state records are never scored and open predictions are
  unscored, never assumed.
- renderPredictionRange: §4 duration/day forms, stored on the record.

Tests (src/quota-arrival.test.ts, 20 tests) name the design record
as their oracle. The live wiring (gatherer tick ->
quota-predictions.jsonl + Turso mirror under source
"quota-prediction") is a follow-up slice; #13260 stays open on it
and on the §4 calendar rendering form.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 16483081-10c5-4f67-b36d-028442ce88bb
Commits

Reviewing files that changed from the base of the PR and between 83c28ba and 1e24f50.

Files selected for processing: 2

  • pm-stack/aggregator/src/quota-arrival.test.ts
  • pm-stack/aggregator/src/quota-arrival.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 merged commit 5c8e163 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the lane-we-13260 branch November 23, 2026 13:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e24f50b10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +232 to +234
test("every builder-emitted record validates", () => {
for (const rec of buildArrivalRecords(baseInput)) expect(() => validateArrivalRecord(rec)).not.toThrow();
expect(() => validateArrivalRecord(predicted())).not.toThrow();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cover arrival invariants with generated property tests

The new suite checks its claimed “every builder-emitted record validates” invariant against only two fixed fixtures, and contains no generated property/model coverage. The repository testing doctrine requires PBT where code has invariants and MBT where a specification exists; this module has both explicit range/state invariants and the cited C4 design. Add generated histories and cadences covering bounded predictions, honesty states, pool isolation, and duplicate/order invariance rather than relying exclusively on handwritten examples.

AGENTS.md reference: AGENTS.md:L37-L39

Useful? React with 👍 / 👎.

Comment on lines +247 to +248
const earliest = last + minI;
const latest = last + maxI;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop emitting detector predictions after their window expires

When issuance occurs more than the longest measured interval after the last arrival, these bounds are entirely in the past, but the builder still publishes a validated predicted record. For example, arrivals on days 0, 10, and 25 issued on day 50 produce a day 35–40 prediction and a negative “days from now” rendering. Unchanged history will keep emitting this expired forecast at every subsequent issuance. Check the bounds against issuedMs and emit a named honesty state when the next-arrival window has already elapsed rather than publishing a retrospective prediction.

Useful? React with 👍 / 👎.

Comment on lines +237 to +239
const instants = arrivalInstants(input.detectorFindings, input.subject.pool);
if (instants.length >= 2) {
evidenceSeen = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Classify a single recorded arrival as insufficient history

With exactly one matching plan-change finding and no vendor cadence, this branch never sets evidenceSeen, so the final record is no_basis despite having detector-history evidence. This contradicts the builder's documented distinction between no evidence and evidence that cannot bound a range, and makes the first observed arrival indistinguishable from an empty history to state consumers. Mark evidence as present whenever at least one attributable arrival exists, while retaining the explanation that no interval is measurable.

Useful? React with 👍 / 👎.

Comment on lines +232 to +234
test("every builder-emitted record validates", () => {
for (const rec of buildArrivalRecords(baseInput)) expect(() => validateArrivalRecord(rec)).not.toThrow();
expect(() => validateArrivalRecord(predicted())).not.toThrow();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cover arrival invariants with generated property tests

The claimed “every builder-emitted record validates” invariant is checked only against two fixed fixtures, and the rest of this new suite likewise contains only hand-written examples. The repository testing doctrine requires PBT where code has invariants and MBT where a specification exists; this module has both explicit range/state invariants and the cited C4 design. Add generated histories and cadences covering bounded predictions, honesty states, pool isolation, and duplicate/order invariance rather than relying exclusively on handwritten examples.

AGENTS.md reference: AGENTS.md:L37-L39

Useful? React with 👍 / 👎.

Comment on lines +183 to +184
if (f.detector !== "plan-change") continue;
if (f.providerId !== pool) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve pool identity for limit-change findings before filtering

When supplied with S5 findings from quota-limit changes, this filter discards every arrival: observeLimitRecord in quota-anomaly.ts:661–680 always sets providerId: null, and both runAnomalyReplay and the live tick append those findings without enriching that identity. Consequently, even a pool with several measured limit changes produces no_basis unless its window kinds also changed; the tests conceal this by constructing limit-change findings with a populated provider ID. Resolve known service IDs through the existing FORECAST_POOLS service-to-provider mapping before filtering, or populate provider identity in the producer, while continuing to reject genuinely unattributable findings.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T13:09:44.067142Z 1e24f50 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant